<?php

/**
 * @author Thibaut Cromphaut, Gaïtano Boeraeve, Mathias Helin, Dimitry Dierickx
 * @copyright  Copyright (c) 2011 Artevelde University College Ghent 
 */

class Application_Model_User extends Ahs_Model
{

    /**
     * @var integer
     */
    protected $_id;
    /**
     * @var string
     */
    protected $_givenname;
    /**
     * @var string
     */
    protected $_familyname;
    /**
     * @var string
     */
    protected $_password;
    /**
     * @var string
     */
    protected $_role_id;
    /**
     * @var string
     */
    protected $_avatar;
    /**
     * @var enum
     */
    protected $_title;
    /**
     * @var string
     */
    protected $_bio;
    /**
     * @var string
     */
    protected $_addressline;
    /**
     * @var string
     */
    protected $_postcode;
    /**
     * @var string
     */
    protected $_city;
    /**
     * @var integer
     */
    protected $_country_id;
    /**
     * @var date
     */
    protected $_dob;
    /**
     * @var integer
     */
    protected $_secretquestion_id;
    /**
     * @var string
     */
    protected $_secretanswer;
    /**
     * @var bool
     */
    protected $_prefnewsletter;
    /**
     * @var datetime
     */
    protected $_activedate;
    /**
     * @var datetime
     */
    protected $_creationdate;
    /**
     * @var datetime
     */
    protected $_modifieddate;
    /**
     * @var datetime
     */
    protected $_deleteddate;
    /**
     * @var datetime
     */
    protected $_lastlogindate;
    
    
    /**
     * @return integer 
     */
    public function getId() {
        return $this->_id;
    }
    /**
     * @param integer $id 
     */
    public function setId($id) {
        $this->_id = $id;
    }
    
    /**
     * @return string 
     */
    public function getGivenname() {
        return $this->_givenname;
    }
    /**
     * @param string $givenname 
     */
    public function setGivenname($givenname) {
        $this->_givenname = $givenname;
    }
    
    /**
     * @return string 
     */
    public function getFamilyname() {
        return $this->_familyname;
    }
    /**
     * @param string $familyname 
     */
    public function setFamilyname($familyname) {
        $this->_familyname = $familyname;
    }
    
    /**
     * Get the user's full name
     * @return string 
     */
    public function getFullname()
    {
        return $this->_givenname." ".$this->_familyname;
    }
    
    /**
     * @return string 
     */
    public function getPassword() {
        return $this->_password;
    }
    /**
     * @param string $password 
     */
    public function setPassword($password) {
        $this->_password = Ahs_Utility::hash($password);
    }
    
    /**
     * @return integer 
     */
    public function getRoleId() {
        return $this->_role_id;
    }
    /**
     * @param integer $role_id 
     */
    public function setRoleId($role_id) {
        $this->_role_id = $role_id;
    }
    /**
     * @return Application_Model_Role 
     */
    public function getRole()
    {
        if($this->_role_id != null)
        {
            $mapper = new Application_Model_RoleMapper();
            return $mapper->fetchById($this->_role_id);
        }
        
        return null;
    }
    
    /**
     * @return string 
     */
    public function getAvatar() {
        return $this->_avatar;
    }
    /**
     * @param string $avatar 
     */
    public function setAvatar($avatar) {
        $this->_avatar = $avatar;
    }
    /**
     * @return string
     */
    public function getAvatarUrl()
    {
        $path   = '/assets/users/';
        if($this->_avatar != null)
            return $path.$this->_avatar;
        return $path.'noavatar.png';
    }
    
    /**
     * @return string 
     */
    public function getTitle() {
        return $this->_title;
    }
    /**
     * @param string $title 
     */
    public function setTitle($title) {
        $this->_title = $title;
    }
    
    /**
     * @return string
     */
    public function getBio() {
        return $this->_bio;
    }
    /**
     * @param string
     */
    public function setBio($bio) {
        $this->_bio = $bio;
    }
    
    /**
     * @return string 
     */
    public function getAddressline() {
        return $this->_addressline;
    }
    /**
     * @param string $addressline 
     */
    public function setAddressline($addressline) {
        $this->_addressline = $addressline;
    }
    
    /**
     * @return string 
     */
    public function getPostcode() {
        return $this->_postcode;
    }
    /**
     * @param string $postcode 
     */
    public function setPostcode($postcode) {
        $this->_postcode = $postcode;
    }
    
    /**
     * @return string 
     */
    public function getCity() {
        return $this->_city;
    }
    /**
     * @param string $city 
     */
    public function setCity($_city) {
        $this->_city = $_city;
    }
    
    /**
     * @return integer 
     */
    public function getCountryId() {
        return $this->_country_id;
    }
    /**
     * @param integer $country_id 
     */
    public function setCountryId($country_id) {
        $this->_country_id = $country_id;
    }
    /**
     * @return Application_Model_Country 
     */
    public function getCountry()
    {
        if($this->_country_id != null)
        {
            $mapper = new Application_Model_CountryMapper();
            return $mapper->fetchById($this->_country_id);
        }
        
        return null;
    }
    
    /**
     * @return date 
     */
    public function getDob() {
        return $this->_dob;
    }
    /**
     * @param date $dob 
     */
    public function setDob($dob) {
        $this->_dob = $dob;
    }
    
    /**
     * @return integer 
     */
    public function getSecretquestionId() {
        return $this->_secretquestion_id;
    }
    /**
     * @param integer $secretquestion_id 
     */
    public function setSecretquestionId($secretquestion_id) {
        $this->_secretquestion_id = $secretquestion_id;
    }
    /**
     * @return Application_Model_Secretquestion
     */
    public function getSecretquestion()
    {
        if($this->_secretquestion_id != null)
        {
            $mapper = new Application_Model_SecretquestionMapper();
            return $mapper->fetchById($this->_secretquestion_id);
        }
        
        return null;
    }
    
    /**
     * @return string 
     */
    public function getSecretanswer() {
        return $this->_secretanswer;
    }
    /**
     * @param string $secretanswer 
     */
    public function setSecretanswer($secretanswer) {
        $this->_secretanswer = $secretanswer;
    }
    
    /**
     * @return boolean 
     */
    public function getPrefnewsletter() {
        return $this->_prefnewsletter;
    }
    /**
     * @param boolean $prefnewsletter 
     */
    public function setPrefnewsletter($prefnewsletter) {
        $this->_prefnewsletter = $prefnewsletter;
    }
    
    /**
     * @return datetime 
     */
    public function getActiveDate() {
        return $this->_activedate;
    }
    /**
     * @param datetime $activedate 
     */
    public function setActiveDate($activedate) {
        $this->_activedate = $activedate;
    }
    
    /**
     * @return datetime 
     */
    public function getCreationDate() {
        return $this->_creationdate;
    }
    /**
     * @param datetime $creationdate 
     */
    public function setCreationDate($creationdate) {
        $this->_creationdate = $creationdate;
    }
    
    /**
     * @return datetime 
     */
    public function getModifiedDate() {
        return $this->_modifieddate;
    }
    /**
     * @param datetime $modifieddate 
     */
    public function setModifiedDate($modifieddate) {
        $this->_modifieddate = $modifieddate;
    }
    
    /**
     * @return datetime 
     */
    public function getDeletedDate() {
        return $this->_deleteddate;
    }
    /**
     * @param datetime $deleteddate 
     */
    public function setDeletedDate($deleteddate) {
        $this->_deleteddate = $deleteddate;
    }
    
    /**
     * @return datetime 
     */
    public function getLastloginDate() {
        return $this->_lastlogindate;
    }
    /**
     * @param datetime $lastlogindate 
     */
    public function setLastloginDate($lastlogindate) {
        $this->_lastlogindate = $lastlogindate;
    }
    
    /**
     * Get all book IDs this user is subscribed to
     * @return Array 
     */
    public function getBookIds()
    {
        if($this->_id != null)
        {
            $mapper = new Application_Model_UserMapper();
            return $mapper->getUserBookIds($this->_id);
        }
        
        return null;
    }
    
    /**
     * Get all courses this user is subscribed to
     * @return Array 
     */
    public function getCourses()
    {
        if($this->_id != null)
        {
            $mapper = new Application_Model_CourseMapper();
            return $mapper->fetchReadingListByUserId($this->_id);
        }
        
        return null;
    }
    
    /**
     * Get all course IDs this user is subscribed to
     * @return Array 
     */
    public function getCourseIds()
    {
        if($this->_id != null)
        {
            $mapper = new Application_Model_UserMapper();
            return $mapper->getUserCourseIds($this->_id);
        }
        
        return null;
    }
    
    /**
     * Get all email addresses for this user
     * return Array(Application_Model_UserHasEmail)
     */
    public function getEmails()
    {
        if($this->_id != null)
        {
            $mapper = new Application_Model_UserHasEmailMapper();
            return $mapper->fetchByUserId($this->_id);
        }
        
        return null;
    }
    
    /**
     * Get the user's primary email address
     */
    public function getPrimaryEmail()
    {
        if($this->_id != null)
        {
            $mapper = new Application_Model_UserHasEmailMapper();
            return $mapper->fetchPrimaryByUserId($this->_id);
        }
        
        return null;
    }
}


